/*
 *  ckr_spec_SpecListener.h
 *  ckrSpec
 *
 *  Created by C. Keith Ray on 2006.11.08.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#pragma once

#include <string>
#include <sstream>

namespace  ckr
{

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class SpecListener
{
public:
	SpecListener();
	virtual ~SpecListener();

	virtual void specStarted( const std::string& specName );
	virtual void specEnded( const std::string& specName, bool passed );

	virtual void spec_failed( 
			const std::string&	nameIn, 
			int						lineNumberIn, 
			const char*				srcFileNameIn, 
			const std::string&	failMessageIn );
};

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class RecordingFailuresSpecListener : public SpecListener
{
	std::stringstream log;

public:

	RecordingFailuresSpecListener();

	virtual ~RecordingFailuresSpecListener();

	virtual void specStarted( const std::string& specName );

	virtual void spec_failed( 
			const std::string&	nameIn, 
			int						lineNumberIn, 
			const char*				srcFileNameIn, 
			const std::string&	failMessageIn );

	virtual std::string logStr() const;

};

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class StdOutStreamSpecListener : public RecordingFailuresSpecListener
{
	std::ostream& strmOut;

public:

	StdOutStreamSpecListener( std::ostream& strm );

	virtual ~StdOutStreamSpecListener();

	virtual void specEnded( const std::string& specName, bool passed );
};

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

}; // end namespace


